package com.toe.forum.webapi.controller;

import com.toe.common.restful.JsonPage;
import com.toe.common.restful.JsonResult;
import com.toe.forum.service.ISearchService;
import com.toe.pojo.dto.forum.SearchDTO;
import com.toe.pojo.entity.forum.ArticleElasticsearch;
import com.toe.pojo.vo.forum.ArticleDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/search")
@Api(tags = "搜索模块")
public class SearchController {

    @Autowired
    private ISearchService searchService;

    @ApiOperation("搜索符合全部条件的数据")
    @PostMapping("/search/article")
    public JsonResult<List<ArticleDetailVO>> searchAll(String keywords){
        List<ArticleDetailVO> search = searchService.search(keywords);
        return JsonResult.ok(search);
    }

    @ApiOperation("分页搜索符合全部条件的数据")
    @PostMapping("/search/article/page")
    public JsonResult<JsonPage<ArticleDetailVO>> searchAllPage(@RequestBody SearchDTO searchDTO){
        String keyword = searchDTO.getKeyWord();
        Integer page = searchDTO.getPageNum();
        Integer pageSize = searchDTO.getPageSize();
        JsonPage<ArticleDetailVO> search = searchService.search(keyword, page, pageSize);
        return JsonResult.ok(search);
    }
}
